package demo.state;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-26
 */
public class Test {
    public static void main(String[] args) {
        T t = new T();
        System.out.println(t.getState());
        t.start();
        while (Thread.State.TERMINATED != t.getState()) {
            System.out.println(t.getState());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(t.getState());

    }
}

class T extends Thread {
    public int count = 0;
    @Override
    public void run() {
        while (true) {
            count++;
            System.out.println("子线程执行");
            if (count >= 10) {
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

